#include <QMessageBox>
#include "DialogNewMap.hpp"
#include "ui_DialogNewMap.h"
#include "Is.hpp"

DialogNewMap::DialogNewMap(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogNewMap),
    _canCreateNewMap(false),
    _mapWidth(0),
    _mapHeight(0)
{
    ui->setupUi(this);

    QObject::connect(ui->pushButtonCreate, SIGNAL(clicked()), this, SLOT(buttonActionNewMap()));
    QObject::connect(ui->pushButtonCancel, SIGNAL(clicked()), this, SLOT(close()));
}

DialogNewMap::~DialogNewMap()
{
    delete ui;
}

void    DialogNewMap::buttonActionNewMap()
{
    QString mapWidth = ui->lineEditMapWidth->text();
    QString mapHeight = ui->lineEditMapWidth->text();

    if (mapWidth != "" && mapHeight != "" && Is::isNum(mapWidth) && Is::isNum(mapHeight))
    {
        _mapWidth = mapWidth.toInt();
        _mapHeight = mapHeight.toInt();
        _canCreateNewMap = true;
        this->close();
    }
    else
        QMessageBox::critical(this, "Error", "Please fill the fields tile width and tile height with integer values.");

}

bool    DialogNewMap::canCreateNewMap() const
{
    return _canCreateNewMap;
}

int     DialogNewMap::getMapWidth() const
{
    return _mapWidth;
}

int     DialogNewMap::getMapHeight() const
{
    return _mapHeight;
}


